/ ch8list2.cpp
// Class Definitions for ListOfContracts
// File: ch8list2.cpp

#include <iostream.h>
#include "ch8list2.h"



ListOfContracts :: ListOfContracts()
{
	numContracts = 0;
}


void ListOfContracts :: Add(Contract contract)
{
	if (numContracts < MAX_CONTRACTS)  // Is there room on the list?
	{

		int contractNum = contract.ProvideID();
		int index = Search(contractNum);

		if (index == numContracts) // contract with this ID does not exist
		{
			listOfContracts[numContracts] = contract; // copy contract into list
			numContracts++;
		}
		else
		{	cout << "\nA contract with this ID already exists.\n";
		}
	}
	else
	{	cout << "There was no room to add the contract\n\n";
	}
}

void ListOfContracts :: Delete(int contractNum)
{
	int index;
	index = Search(contractNum);
	if (index <  numContracts) // the contract to be deleted exists
	{	for (int i = index; i < numContracts - 1; i++)
		{	listOfContracts[i] = listOfContracts[i+1];
		}
		numContracts--;
	}
	else
	{	cout << "Invalid Contract ID\n\n";
	}
}

int ListOfContracts ::  Search(int contractID)
{
	int index;
	for (index = 0; index < numContracts; index++)
	{	if (contractID == listOfContracts[index].ProvideID())
			{	return index;
			}
	}
	return index;
}



bool ListOfContracts :: FindContract(int ID, Contract& contract)
{
	int index = 0;
	while (index < numContracts) // keep searching until ID found
															  // or no more contracts
	{	if (ID == listOfContracts[index].ProvideID())
		{	contract = listOfContracts[index];
			return TRUE;

		}
		else
		{	index++;
		}
	}
	return FALSE;  // contract ID not found in list
}

void ListOfContracts :: ReplaceContract (Contract contract)

{
	int index;;
	int ID = contract.ProvideID();  // Get ID of the contract so we can find it in
											  // in the list.
	index = Search(ID);
	if (index < numContracts) // the contract to be replaced exists
	{	listOfContracts[index] = contract;
	}
	else
	{	cout << "\nContract to be replaced does not exist in the list.\n";
	}
}

void ListOfContracts :: DisplayAll()
{
	int contractID;
	int sqFootage;
	int numDesks;
	int numDays;
	double charge;

	cout << endl << endl;  // To set off the output
	for (int contract = 0; contract < numContracts; contract++)
	{
		contractID = listOfContracts[contract].ProvideID();
		sqFootage = listOfContracts[contract].ProvideSquareFootage();
		cout << "The square footage for contract " <<contractID << " is: "
			  << sqFootage << endl;

		numDesks = listOfContracts[contract].ProvideNumberOfDesks();
		cout << "The number of desks for contract " << contractID << " is: "
			  << numDesks << endl;

		numDays = listOfContracts[contract].ProvideNumberOfDays();
		cout << "The number of days for contract " << contractID << " is: "
			  << numDays << endl;


		charge = listOfContracts[contract].ProvidePerWeekCharge();
		cout << "The per week charge for contract " << contractID <<"  is: "
			 << charge << endl;
		cout << endl << endl;
	}

}